package com.ruoyi.gis.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.gis.domain.*;
import com.ruoyi.gis.service.DeviceDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/gis/data/yc")
public class GisDataYcController extends BaseController {

    @Autowired
    private DeviceDataService deviceDataService;

    @GetMapping("/listData/{deviceCode}")
    public AjaxResult listData(@PathVariable("deviceCode") String deviceCode)
    {

        List<YcclData> list = deviceDataService.selectDataListByDevice(deviceCode);
        return AjaxResult.success(list);
    }

    @GetMapping("/listData/trjc/dataTypes/{deviceCode}")
    public AjaxResult listTrjcDataType(@PathVariable("deviceCode") String deviceCode)
    {
        List<YcDeviceTrType> list = deviceDataService.listTrjcDataType(deviceCode);
        return AjaxResult.success(list);
    }

    @GetMapping("/listData/trjc/{deviceCode}/{varName}")
    public AjaxResult listTrjcData(@PathVariable("deviceCode") String deviceCode,
                                   @PathVariable("varName") String varName)
    {
        //主板温度
        List<YcDeviceTrType> trTypes = deviceDataService.
                listTrjcDataType(deviceCode);
        if(trTypes==null)return AjaxResult.success("设备无数据");
        List<YcDeviceTrData> list = deviceDataService.
                selectTrDataListByDevice(deviceCode,varName);
        return AjaxResult.success(list);
    }

    //气象数据
    @GetMapping("/listData/qx/{deviceCode}")
    public AjaxResult listQxData(@PathVariable("deviceCode") String deviceCode)
    {
        List<YcDeviceQxData> list = deviceDataService.listQxData(deviceCode);
        return AjaxResult.success(list);
    }
}
